#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class Solution
{
public:
    vector<vector<int>> flipAndInvertImage(vector<vector<int>> &image)
    {

        auto swap = [](int a, int b)
        {
            int t = a;
            a = b;
            b = t;
        };
        int n = image.size();
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                //  水平 翻转图像
                if (image[i][j] != image[i][n - j - 1])
                {
                    int t = image[i][j];
                    image[i][j] = image[i][n - j - 1];
                    image[i][n - j - 1] = t;
                }
            }
        }

        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                //  反转 图像
                image[i][j] ^= 1;
            }
        }
        return image;
    }

    vector<vector<int>> flipAndInvertImage_2(vector<vector<int>> &image)
    {
        int n = image.size();
        for (int i = 0; i < n; i++)
        {
            int left = 0, right = n - 1;
            while (left < right)
            {
                if (image[i][left] == image[i][right])
                {
                    image[i][left] ^= 1;
                    image[i][right] ^= 1;
                }
                left++;
                right--;
            }
            if (left == right)
            {
                image[i][left] ^= 1;
            }
        }
        return image;
    }

    vector<vector<int>> flipAndInvertImage_3(vector<vector<int>> &A)
    {
        int n = A.size();

        for (int i = 0; i < n; i++)
        {
            reverse(A[i].begin(), A[i].end());
            for (int j = 0; j < n; j++)
            {
                A[i][j] = !A[i][j];
            }
        }
        return A;
    }
};
int main()
{
    Solution s;
    vector<vector<int>> image = {{1, 1, 0}, {1, 0, 1}, {0, 0, 0}};
    s.flipAndInvertImage_3(image);
    int n = image.size();
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            cout << image[i][j] << " ";
        }
        cout << endl;
    }
    system("pause");
    return 0;
}
